package com.stockz.equity.indicator.vsa.property;

import java.util.List;

import com.stockz.equity.indicator.vsa.VsaBar;
import com.stockz.equity.model.Bar;

public class Volume extends RangeEnum {
	
	public static final Volume Climatic = new Volume("Climatic",1,Double.MAX_VALUE,501);
	public static final Volume UltraHigh = new Volume("UltraHigh",1,500,251);
	public static final Volume High = new Volume("High",2,250,126);
	public static final Volume Average = new Volume("Average",3,125,51);
	public static final Volume Low = new Volume("Low",4,50,0);
	
	private static final Volume[] volumes = new Volume[]{Climatic,UltraHigh,High,Average,Low};
	
	public static Volume[] values(){
		return volumes;
	}
	
	public static void analyze(List<Bar> barList,double[] vsma, int index, VsaBar vsaBar){
		if(barList == null || barList.isEmpty() || vsma == null || 0 == vsma.length || 
				index < 0 || index >= barList.size() || index >= vsma.length || vsaBar == null || vsma[index] == 0){
			return;
		}
		double percentage = barList.get(index).getVolume()*100/vsma[index];
		for(Volume volume : Volume.values()){
			if(percentage <= volume.getUpperLimit() && percentage >= volume.getLowerLimit()){
				vsaBar.setVolume(volume);
				break;
			}
		}
	}
	
	private Volume(String name,int ordinal, double upperLimit,double lowerLimit){
		super(name,ordinal,upperLimit,lowerLimit);
	}
}
